
/*
 * @Descripttion: 
 * @version: 
 * @Author: 高月飞
 * @Date: 2023-11-15 19:54:32
 * @LastEditors: 高月飞
 * @LastEditTime: 2023-11-25 21:00:31
 */
import { ref, onMounted } from "vue"
import type { Ref } from 'vue'
import { on } from "events";
import { getUidSystemEmployeeToInfoApi, userSystemEmployeeListApi } from "@/services/employee";
type IUserInfo = {
    id?: number
    url?: string
    username?: string;
    realname?: string;
    sex?: string;
    phone?: string;
    birthday?: string;
    avatar?: string;
    role?: number | string;

}
/**
 * 处理dialogVisible
 */
export const userDialogVisible = (visible = false): [Ref<boolean>, (visible: boolean, callback?: () => void) => void] => {
    const data = ref(false)
    const setData = (visible: boolean, callback: () => void = () => { }) => {
        data.value = visible
        callback()
    }
    return [data, setData]
}

//用户列表数据
export const useUserList = (pageNum = 1, query = {}): [Ref<IUserInfo[]>, Ref<number>, (page?: number, query?: object) => Promise<void>] => {
    const data = ref<IUserInfo[]>([])
    const total = ref(0)

    const loadData = async (page = 1, query = {}) => {
        let ret = await userSystemEmployeeListApi(page, query)
        if (ret.code === 200) {
            data.value = ret.data.users
            total.value = ret.data.total
        }
    }
    onMounted(() => {
        loadData(pageNum, query)
    })
    return [data, total, loadData]
}



//修改用户给定的id进行数据的回显
export const useUserInfo = (id: number, callback: (data: IUserInfo) => void) => {
    onMounted(async () => {
        let ret = await getUidSystemEmployeeToInfoApi(id)
        callback(ret.data)
    })

}






/**
 * 知识点
 * callback: () => void = () => { } 表示 callback 是一个可选的回调函数参数，并且它的默认值是一个空函数。
 * callback: () => void 表示 callback 是一个函数类型，它不接受任何参数，并且不返回任何值（即 void）。= () => { } 表示如果没有提供 callback 参数的值，默认值就是一个空函数，即一个没有任何操作的函数。
 */